package logic

import (
	"cartsrv/cartsrv"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLogic {
	return &CartAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartAddLogic) CartAdd(req *types.CartAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.CartSrv.CartAdd(l.ctx, &cartsrv.CartAddRequest{
		UserId:  req.UserId,
		GoodsId: req.GoodsId,
		Number:  req.Number,
	})
	if err != nil {
		return &types.Response{
			Code:   500,
			Messae: err.Error(),
			Data:   nil,
		}, nil
	}
	return &types.Response{
		Code:   200,
		Messae: "购物车添加成功",
		Data:   add,
	}, nil
}
